//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MTAG_EIC.h"
#include "uListePays.h"

#define MODULE_TAG MTAG_ULISTEPAYS

//---------------------------------------------------------------------------

#pragma package(smart_init)

__fastcall TListePays::TListePays()
{
  ASSERT(DERNIER == 244);

struct STRUCT
  {
  char* szPays;
  char* szCodeISO;
  int iID;
  };

//--------------------------------------------------------------------------------

//                        INITIALISATION DE "TabPays[]"
//                   (Uniquement utilisé pour le format TDFC)
//--------------------------------------------------------------------------------
STRUCT TabPays[] = { {"AFGHANISTAN"                                 , "AF",AFGHANISTAN},
                     {"AFRIQUE DU SUD"                              , "ZA",AFRIQUE_DU_SUD},
                     {"ALBANIE"                                     , "AL",ALBANIE},
                     {"ALGERIE"                                     , "DZ",ALGERIE},
                     {"ALLEMAGNE"                                   , "DE",ALLEMAGNE},
                     {"ANDORRE"                                     , "AD",ANDORRE},
                     {"ANGOLA"                                      , "AO",ANGOLA},
                     {"ANGUILLA"                                    , "AI",ANGUILLA},
                     {"ANTARCTIQUE"                                 , "AQ",ANTARCTIQUE},
                     {"ANTIGUA-ET-BARBUDA"                          , "AG",ANTIGUA_ET_BARBUDA},
                     {"ANTILLES NEERLANDAISES"                      , "AN",ANTILLES_NEERLANDAISES},
                     {"ARABIE SAOUDITE"                             , "SA",ARABIE_SAOUDITE},
                     {"ARGENTINE"                                   , "AR",ARGENTINE},
                     {"ARMENIE"                                     , "AM",ARMENIE},
                     {"ARUBA"                                       , "AW",ARUBA},
                     {"AUSTRALIE"                                   , "AU",AUSTRALIE},
                     {"AUTRICHE"                                    , "AT",AUTRICHE},
                     {"AZERBAIDJAN"                                 , "AZ",AZERBAIDJAN},
                     {"BAHAMAS"                                     , "BS",BAHAMAS},
                     {"BAHREIN"                                     , "BH",BAHREIN},
                     {"BANGLADESH"                                  , "BD",BANGLADESH},
                     {"BARBADE"                                     , "BB",BARBADE},
                     {"BELARUS"                                     , "BY",BELARUS},
                     {"BELGIQUE"                                    , "BE",BELGIQUE},
                     {"BELIZE"                                      , "BZ",BELIZE},
                     {"BENIN"                                       , "BJ",BENIN},
                     {"BERMUDES"                                    , "BM",BERMUDES},
                     {"BHOUTAN"                                     , "BT",BHOUTAN},
                     {"BOLIVIE"                                     , "BO",BOLIVIE},
                     {"BOSNIE-HERZEGOVINE"                          , "BA",BOSNIE_HERZEGOVINE},
                     {"BOTSWANA"                                    , "BW",BOTSWANA},
                     {"BOUVET, ILE"                                 , "BV",BOUVET_ILE},
                     {"BRESIL"                                      , "BR",BRESIL},
                     {"BRUNEI DARUSSALAM"                           , "BN",BRUNEI_DARUSSALAM},
                     {"BULGARIE"                                    , "BG",BULGARIE},
                     {"BURKINA FASO"                                , "BF",BURKINA_FASO},
                     {"BURUNDI"                                     , "BI",BURUNDI},
                     {"CAIMANES, ILES"                              , "KY",CAIMANES_ILES},
                     {"CAMBODGE"                                    , "KH",CAMBODGE},
                     {"CAMEROUN"                                    , "CM",CAMEROUN},
                     {"CANADA"                                      , "CA",CANADA},
                     {"CAP-VERT"                                    , "CV",CAP_VERT},
                     {"CENTREAFRICAINE, REPUBLIQUE"                 , "CF",CENTREAFRICAINE_REPUBLIQUE},
                     {"CHILI"                                       , "CL",CHILI},
                     {"CHINE"                                       , "CN",CHINE},
                     {"CHRISTMAS, ILE"                              , "CX",CHRISTMAS_ILE},
                     {"CHYPRE"                                      , "CY",CHYPRE},
                     {"COCOS (KEELING), ILES DES"                   , "CC",COCOS_KEELING_ILES_DES},
                     {"COLOMBIE"                                    , "CO",COLOMBIE},
                     {"COMORES"                                     , "KM",COMORES},
                     {"CONGO"                                       , "CG",CONGO},
                     {"COOK, ILES"                                  , "CK",COOK_ILES},
                     {"COREE, REPUBLIQUE DE"                        , "KR",COREE_REPUBLIQUE_DE},
                     {"COREE, REPUBLIQUE POPULAIRE DEMOCRATIQUE DE" , "KP",COREE_REPUBLIQUE_POPULAIRE_DEMOCRATIQUE_DE},
                     {"COSTA RICA"                                  , "CR",COSTA_RICA},
                     {"COTE D'IVOIRE"                               , "CI",COTE_D_IVOIRE},
                     {"CROATIE"                                     , "HR",CROATIE},
                     {"CUBA"                                        , "CU",CUBA},
                     {"DANEMARK"                                    , "DK",DANEMARK},
                     {"DJIBOUTI"                                    , "DJ",DJIBOUTI},
                     {"DOMINICAINE, REPUBLIQUE"                     , "DO",DOMINICAINE_REPUBLIQUE},
                     {"DOMINIQUE"                                   , "DM",DOMINIQUE},
                     {"EGYPTE"                                      , "EG",EGYPTE},
                     {"EL SALVADOR"                                 , "SV",EL_SALVADOR},
                     {"EMIRATS ARABES UNIS"                         , "AE",EMIRATS_ARABES_UNIS},
                     {"EQUATEUR"                                    , "EC",EQUATEUR},
                     {"ERYTHEE"                                     , "ER",ERYTHEE},
                     {"ESPAGNE"                                     , "ES",ESPAGNE},
                     {"ESTONIE"                                     , "EE",ESTONIE},
                     {"ETATS-UNIS"                                  , "US",ETATS_UNIS},
                     {"ETHIOPIE"                                    , "ET",ETHIOPIE},
                     {"EX-REPUBLIQUE YOUGOSLAVE DE MACEDOINE"       , "MK",EX_REPUBLIQUE_YOUGOSLAVE_DE_MACEDOINE},
                     {"FALKLAND, ILE (MALVINAS)"                    , "FK",FALKLAND_ILE_MALVINAS},
                     {"FEROE, ILES"                                 , "FO",FEROE_ILES},
                     {"FIDJI"                                       , "FJ",FIDJI},
                     {"FINLANDE"                                    , "FI",FINLANDE},
                     {"FRANCE"                                      , "FR",FRANCE},
                     //{"FRANCE METROPOLITAINE"                       , "FX",OLD_FRANCE_METROPOLITAINE},
                     {"GABON"                                       , "GA",GABON},
                     {"GAMBIE"                                      , "GM",GAMBIE},
                     {"GEORGIE"                                     , "GE",GEORGIE},
                     {"GEORGIE DU SUD ET LES ILES SANDWICH DU SUD"  , "GS",GEORGIE_DU_SUD_ET_LES_ILES_SANDWICH_DU_SUD},
                     {"GHANA"                                       , "GH",GHANA},
                     {"GIBRALTAR"                                   , "GI",GIBRALTAR},
                     {"GRECE"                                       , "GR",GRECE},
                     {"GRENADE"                                     , "GD",GRENADE},
                     {"GROENLAND"                                   , "GL",GROENLAND},
                     //{"GUADELOUPE"                                  , "GP",GUADELOUPE},
                     {"GUAM"                                        , "GU",GUAM},
                     {"GUATEMALA"                                   , "GT",GUATEMALA},
                     {"GUINEE"                                      , "GN",GUINEE},
                     {"GUINEE EQUATORIALE"                          , "GQ",GUINEE_EQUATORIALE},
                     {"GUINEE-BISSAU"                               , "GW",GUINEE_BISSAU},
                     {"GUYANA"                                      , "GY",GUYANA},
                     //{"GUYANE FRANCAISE"                            , "GF",GUYANE_FRANCAISE},
                     {"HAITI"                                       , "HT",HAITI},
                     {"HEARD ET LES ILES MCDONALD, ILE"             , "HM",HEARD_ET_LES_ILES_MCDONALD_ILE},
                     {"HONDURAS"                                    , "HN",HONDURAS},
                     {"HONG KONG"                                   , "HK",HONG_KONG},
                     {"HONGRIE"                                     , "HU",HONGRIE},
                     {"ILES MINEURS ELOIGNEES DES ETATS-UNIS"       , "UM",ILES_MINEURS_ELOIGNEES_DES_ETATS_UNIS},
                     {"ILES VIERGES BRITANNIQUES"                   , "VG",ILES_VIERGES_BRITANNIQUES},
                     {"ILES VIERGES (E.U)"                          , "VI",ILES_VIERGES_E_U},
                     {"INDE"                                        , "IN",INDE},
                     {"INDONESIE"                                   , "ID",INDONESIE},
                     {"IRAN, REPUBLIQUE ISLAMAIQUE D'"              , "IR",IRAN_REPUBLIQUE_ISLAMAIQUE_D},
                     {"IRAQ"                                        , "IQ",IRAQ},
                     {"IRLANDE"                                     , "IE",IRLANDE},
                     {"ISLANDE"                                     , "IS",ISLANDE},
                     {"ISRAEL"                                      , "IL",ISRAEL},
                     {"ITALIE"                                      , "IT",ITALIE},
                     {"JAMAIQUE"                                    , "JM",JAMAIQUE},
                     {"JAPON"                                       , "JP",JAPON},
                     {"JORDANIE"                                    , "JO",JORDANIE},
                     {"KAZAKSTAN"                                   , "KZ",KAZAKSTAN},
                     {"KENYA"                                       , "KE",KENYA},
                     {"KIRGHISZISTAN"                               , "KG",KIRGHISZISTAN},
                     {"KIRIBATI"                                    , "KI",KIRIBATI},
                     {"KOWEIT"                                      , "KW",KOWEIT},
                     {"LAO, REPUBLIQUE DEMOCRATIQUE POPULAIRE"      , "LA",LAO_REPUBLIQUE_DEMOCRATIQUE_POPULAIRE},
                     {"LESOTHO"                                     , "LS",LESOTHO},
                     {"LETTONIE"                                    , "LV",LETTONIE},
                     {"LIBAN"                                       , "LB",LIBAN},
                     {"LIBERIA"                                     , "LR",LIBERIA},
                     {"LIBYENNE, JAMAHIRIYA ARABE"                  , "LY",LIBYENNE_JAMAHIRIYA_ARABE},
                     {"LIECHTENSTEIN"                               , "LI",LIECHTENSTEIN},
                     {"LITUANIE"                                    , "LT",LITUANIE},
                     {"LUXEMBOURG"                                  , "LU",LUXEMBOURG},
                     {"MACAO"                                       , "MO",MACAO},
                     {"MADAGASCAR"                                  , "MG",MADAGASCAR},
                     {"MALAISIE"                                    , "MY",MALAISIE},
                     {"MALAWI"                                      , "MW",MALAWI},
                     {"MALDIVES"                                    , "MV",MALDIVES},
                     {"MALI"                                        , "ML",MALI},
                     {"MALTE"                                       , "MT",MALTE},
                     {"MARIANNES DU NORD, ILES"                     , "MP",MARIANNES_DU_NORD_ILES},
                     {"MAROC"                                       , "MA",MAROC},
                     {"MARSHALL, ILES"                              , "MH",MARSHALL_ILES},
                     //{"MARTINIQUE"                                  , "MQ",MARTINIQUE},
                     {"MAURICE"                                     , "MU",MAURICE},
                     {"MAURITANIE"                                  , "MR",MAURITANIE},
                     {"MAYOTTE"                                     , "YT",MAYOTTE},
                     {"MEXIQUE"                                     , "MX",MEXIQUE},
                     {"MICRONESIE, ETATS FEDERES DE"                , "FM",MICRONESIE_ETATS_FEDERES_DE},
                     {"MOLDOVA, REPUBLIQUE DE"                      , "MD",MOLDOVA_REPUBLIQUE_DE},
                     {"MONACO"                                      , "MC",MONACO},
                     {"MONGOLIE"                                    , "MN",MONGOLIE},
                     {"MONTSERRAT"                                  , "MS",MONTSERRAT},
                     {"MOZAMBIQUE"                                  , "MZ",MOZAMBIQUE},
                     {"MYANMAR"                                     , "MM",MYANMAR},
                     {"NAMIBIE"                                     , "NA",NAMIBIE},
                     {"NAURU"                                       , "NR",NAURU},
                     {"NEPAL"                                       , "NP",NEPAL},
                     {"NICARAGUA"                                   , "NI",NICARAGUA},
                     {"NIGER"                                       , "NE",NIGER},
                     {"NIGERIA"                                     , "NG",NIGERIA},
                     {"NIOUE"                                       , "NU",NIOUE},
                     {"NORFOLK, ILE"                                , "NF",NORFOLK_ILE},
                     {"NORVEGE"                                     , "NO",NORVEGE},
                     {"NOUVELLE-CALEDONIE"                          , "NC",NOUVELLE_CALEDONIE},
                     {"NOUVELLE-ZELANDE"                            , "NZ",NOUVELLE_ZELANDE},
                     {"OCEAN INDIEN, TERRITOIRE BRITANNIQUE DE L'"  , "IO",OCEAN_INDIEN_TERRITOIRE_BRITANNIQUE_DE_L},
                     {"OMAN"                                        , "OM",OMAN},
                     //{"OUGANDA"                                     , "UG",OLD_OUGANDA},
                     {"OUZBEKISTAN"                                 , "UZ",OUZBEKISTAN},
                     {"PAKISTAN"                                    , "PK",PAKISTAN},
                     {"PALAU"                                       , "PW",PALAU},
                     {"PANAMA"                                      , "PA",PANAMA},
                     {"PAPOUASIE-NOUVELLE GUINEE"                   , "PG",PAPOUASIE_NOUVELLE_GUINEE},
                     {"PARAGUAY"                                    , "PY",PARAGUAY},
                     {"PAYS-BAS"                                    , "NL",PAYS_BAS},
                     {"PEROU"                                       , "PE",PEROU},
                     {"PHILIPPINES"                                 , "PH",PHILIPPINES},
                     {"PITCAIRN"                                    , "PN",PITCAIRN},
                     {"POLOGNE"                                     , "PL",POLOGNE},
                     {"POLYNESIE FRANCAISE"                         , "PF",POLYNESIE_FRANCAISE},
                     {"PORTO RICO"                                  , "PR",PORTO_RICO},
                     {"PORTUGAL"                                    , "PT",PORTUGAL},
                     {"QUATAR"                                      , "QA",QUATAR},
                     //{"REUNION"                                     , "RE",REUNION},
                     {"ROUMANIE"                                    , "RO",ROUMANIE},
                     {"ROYAUME-UNI"                                 , "GB",ROYAUME_UNI},
                     {"RUSSIE, FEDERATION DE"                       , "RU",RUSSIE_FEDERATION_DE},
                     {"RWANDA"                                      , "RW",RWANDA},
                     {"SAHARA OCCIDENTAL"                           , "EH",SAHARA_OCCIDENTAL},
                     {"SAINT-KITTS-ET-NEVIS"                        , "KN",SAINT_KITTS_ET_NEVIS},
                     {"SAINT-MARIN"                                 , "SM",SAINT_MARIN},
                     {"SAINT-PIERRE-ET-MIQUELON"                    , "PM",SAINT_PIERRE_ET_MIQUELON},
                     {"SAINT-VINCENT-ET-GRENADINES"                 , "VC",SAINT_VINCENT_ET_GRENADINES},
                     {"SAINTE-HELENE"                               , "SH",SAINTE_HELENE},
                     {"SAINTE-LUCIE"                                , "LC",SAINTE_LUCIE},
                     {"SALOMON, ILES"                               , "SB",SALOMON_ILES},
                     {"SAMOA"                                       , "WS",SAMOA},
                     {"SAMOA AMERICAINES"                           , "AS",SAMOA_AMERICAINES},
                     {"SAO TOMBE-ET-PRINCIPE"                       , "ST",SAO_TOMBE_ET_PRINCIPE},
                     {"SENEGAL"                                     , "SN",SENEGAL},
                     {"SEYCHELLES"                                  , "SC",SEYCHELLES},
                     {"SIERRA LEONE"                                , "SL",SIERRA_LEONE},
                     {"SINGAPOUR"                                   , "SG",SINGAPOUR},
                     {"SLOVAQUIE"                                   , "SK",SLOVAQUIE},
                     {"SLOVENIE"                                    , "SI",SLOVENIE},
                     {"SOMALIE"                                     , "SO",SOMALIE},
                     {"SOUDAN"                                      , "SD",SOUDAN},
                     {"SRI LANKA"                                   , "LK",SRI_LANKA},
                     {"SUEDE"                                       , "SE",SUEDE},
                     {"SUISSE"                                      , "CH",SUISSE},
                     {"SURINAME"                                    , "SR",SURINAME},
                     {"SVALBARD ET LES ILES MAYEN"                  , "SJ",SVALBARD_ET_LES_ILES_MAYEN},
                     {"SWAZILAND"                                   , "SZ",SWAZILAND},
                     {"SYRIENNE, REPUBLIQUE ARABE"                  , "SY",SYRIENNE_REPUBLIQUE_ARABE},
                     {"TADJIKISTAN"                                 , "TJ",TADJIKISTAN},
                     {"TAIWAN, PROVINCE DE CHINE"                   , "TW",TAIWAN_PROVINCE_DE_CHINE},
                     {"TANZANIE, REPUBLIQUE DE"                     , "TZ",TANZANIE_REPUBLIQUE_DE},
                     {"TCHAD"                                       , "TD",TCHAD},
                     {"TCHEQUE, REPUBLIQUE"                         , "CZ",TCHEQUE_REPUBLIQUE},
                     {"TERRES AUSTRALES FRANCAISES"                 , "TF",TERRES_AUSTRALES_FRANCAISES},
                     {"THAILANDE"                                   , "TH",THAILANDE},
                     {"TIMOR ORIENTAL"                              , "TP",TIMOR_ORIENTAL},
                     {"TOGO"                                        , "TG",TOGO},
                     {"TOKELAOU"                                    , "TK",TOKELAOU},
                     {"TONGA"                                       , "TO",TONGA},
                     {"TRINITE-ET-TOBAGO"                           , "TT",TRINITE_ET_TOBAGO},
                     {"TUNISIE"                                     , "TN",TUNISIE},
                     {"TURKMENISTAN"                                , "TM",TURKMENISTAN},
                     {"TURQUES ET CAIQUES, ILES"                    , "TC",TURQUES_ET_CAIQUES_ILES},
                     {"TURQUIE"                                     , "TR",TURQUIE},
                     {"TUVALU"                                      , "TV",TUVALU},
                     {"UKRAINE"                                     , "UA",UKRAINE},
                     {"URUGUAY"                                     , "UY",URUGUAY},
                     {"VANUATU"                                     , "VU",VANUATU},
                     {"VATICAN, ETAT DE LA CITE DU SAINT-SIEGE"     , "VA",VATICAN_ETAT_DE_LA_CITE_DU_SAINT_SIEGE},
                     {"VENEZUELA"                                   , "VE",VENEZUELA},
                     {"VIET NAM"                                    , "VN",VIET_NAM},
                     {"WALLIS ET FUTUNA, ILES"                      , "WF",WALLIS_ET_FUTUNA_ILES},
                     {"YEMEN"                                       , "YE",YEMEN},
                     //{"YOUGOSLAVIE"                                 , "YU",OLD_YOUGOSLAVIE},
                     //{"ZAIRE"                                       , "ZR",OLD_ZAIRE},
                     {"ZAMBIE"                                      , "ZM",ZAMBIE},
                     {"ZIMBABWE"                                    , "ZW",ZIMBABWE},
                     {"CONGO, REPUBLIQUE DEMOCRATIQUE DE"           , "CD",CONGO_REPUBLIQUE_DEMOCRATIQUE_DE},
                     {"MONTENEGRO"                                  , "ME",MONTENEGRO},
                     {"PALESTINE, TERRITOIRE"                       , "PS",PALESTINE_TERRITOIRE},
                     {"SERBIE"                                      , "RS",SERBIE},
                     {"UGANDA"                                      , "UG",UGANDA},
                     {""                                            , ""  ,DERNIER}};

try
   {
   slPays = new TStringList;
   for (int i=0 ; TabPays[i].szPays[0] != '\0'; i++)
     slPays->AddObject(AnsiString(TabPays[i].szPays) + "=" + AnsiString(TabPays[i].szCodeISO),(TObject*)TabPays[i].iID);
   }
catch(Exception &e)
   {
   EICDisplayException(TAG(10), e);
   }
}

__fastcall TListePays::~TListePays()
{
try
   {
   delete slPays;     slPays = NULL;
   }
catch(Exception &e)
   {
   EICDisplayException(TAG(20), e);
   }
}

/*******************************************************************************

Fonction :

Paramètres d'entrée :

Paramètres de sortie :

Valeur retournée :
*******************************************************************************/
STRUCT_PAYS __fastcall TListePays::GetTabPays(short shItem) const
{
STRUCT_PAYS sPays;

try
   {
   if (shItem == AUCUN_PAYS)
      {
      sPays.aPays    = EmptyStr;
      sPays.aCodeISO = EmptyStr;
      sPays.iID = -1;
      }
   else
      {
        sPays.aPays    = slPays->Names[shItem];
        sPays.aCodeISO = EXTRAIRE_CH(slPays->Strings[shItem], slPays->Strings[shItem].Pos('=')+1, slPays->Strings[shItem].Length());
        sPays.iID = (int )slPays->Objects[shItem];
        /*for(int i=0; i < slPays->Count ; i++)
        {
          if ((int)slPays->Objects[i] == shItem)
          {
            sPays.aPays    = slPays->Names[i];
            sPays.aCodeISO = EXTRAIRE_CH(slPays->Strings[i], slPays->Strings[i].Pos('=')+1, slPays->Strings[i].Length());
            sPays.iID = (int )slPays->Objects[i];
            //sPays.aPays    = slPays->Names[shItem];
            //sPays.aCodeISO = EXTRAIRE_CH(slPays->Strings[shItem], slPays->Strings[shItem].Pos('=')+1, slPays->Strings[shItem].Length());
            break;
          }
        } */
      }
   }
catch(Exception &e)
   {
   EICDisplayException(TAG(30), e);
   }
return sPays;
}

/*******************************************************************************

Fonction :

Paramètres d'entrée :

Paramètres de sortie :

Valeur retournée :
*******************************************************************************/
short __fastcall TListePays::GetCount() const
{
return slPays->Count;
}
//---------------------------------------------------------------------------
// Fonction permettant de récupérer le nom du Pays en fonction de son Code ISO 3166
//---------------------------------------------------------------------------
AnsiString __fastcall TListePays::CodeISOToNomPays(const AnsiString &aCodeISO) const
{
  try
    {
    for(int i=0; i < slPays->Count ; i++)
      if(aCodeISO == EXTRAIRE_CH(slPays->Strings[i], slPays->Strings[i].Pos('=')+1, slPays->Strings[i].Length()))
        return slPays->Names[i];
    }
  catch(Exception &e)
    {
    EICDisplayException(TAG(1132), e);
    }
return EmptyStr;
}
